package com.crape.faq.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.crape.common.exceptions.DAOException;
import com.crape.common.ibatis.SqlMapClientDaoSupportEx;
import com.crape.common.model.QuestionRef;
import com.crape.faq.dao.IQuestionRefDAO;

@Service
public class QuestionRefDAOImpl extends SqlMapClientDaoSupportEx implements IQuestionRefDAO {

	@Override
	public QuestionRef queryQuestionRef(Long accountid, Long questionid) throws DAOException {
		if (accountid == null || questionid == null) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accountid", accountid);
		params.put("questionid", questionid);
		return (QuestionRef) this.queryObject("queryQuestionRef", params);
	}

	@Override
	public Long countQuestionRefByQuestionid(Long questionid) throws DAOException {
		if (questionid == null) {
			return 0L;
		}
		return (Long) this.queryObject("countQuestionRefByQuestionid", questionid);
	}

	@Override
	public void insertQuestionRef(Long accountid, Long questionid) throws DAOException {
		if (accountid == null || questionid == null) {
			return;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accountid", accountid);
		params.put("questionid", questionid);
		this.insert("insertQuestionRef", params);
	}

	@Override
	public void backupQuestionRef(Long accountid, Long questionid) throws DAOException {
		if (accountid == null || questionid == null) {
			return;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accountid", accountid);
		params.put("questionid", questionid);
		this.insert("backupQuestionRef", params);
	}

	@Override
	public void deleteQuestionRef(Long accountid, Long questionid) throws DAOException {
		if (accountid == null || questionid == null) {
			return;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accountid", accountid);
		params.put("questionid", questionid);
		this.delete("deleteQuestionRef", params);
	}

}
